package indi.zhifa.study2024.consigntest.logic.busy.consign.entity.request;


import cn.hutool.core.date.LocalDateTimeUtil;
import indi.zhifa.core.common.util.CommonUtil;
import indi.zhifa.core.common.web.entity.request.BasePageRequest;
import indi.zhifa.study2024.consigntest.logic.busy.consign.entity.enums.EBillTimeMode;
import indi.zhifa.study2024.consigntest.logic.busy.consign.entity.enums.EHeaderJoinMode;
import indi.zhifa.study2024.consigntest.logic.busy.consign.entity.enums.EItemJoinMode;
import indi.zhifa.study2024.consigntest.logic.busy.consign.entity.enums.EOrderByMode;
import indi.zhifa.study2024.consigntest.logic.busy.consign.entity.mapperIn.ConsignMapperIn;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Data
public class ConsignPageRequest extends BasePageRequest {
    List<Long> itemIdList;
    List<Long> customerIdList;
    List<Long> salesmanIdList;
    Long enterpriseId;
    LocalDate billTimeBeg;
    LocalDate billTimeEnd;

    EHeaderJoinMode headerJoin;
    EItemJoinMode itemJoin;
    EOrderByMode orderBy;
    EBillTimeMode billTimeMode;

    public ConsignMapperIn toMapperIn(){
        ConsignMapperIn consignMapperIn = new ConsignMapperIn();
        consignMapperIn.setItemIdList(itemIdList);
        consignMapperIn.setCustomerIdList(customerIdList);
        consignMapperIn.setSalesmanIdList(salesmanIdList);
        consignMapperIn.setEnterpriseId(enterpriseId);

        LocalDateTime billTimeBegT = billTimeBeg.atTime(0,0,0);
        LocalDateTime billTimeEndT = billTimeEnd.atTime(23,59,59);

        consignMapperIn.setBillTimeBeg(billTimeBegT);
        consignMapperIn.setBillTimeEnd(billTimeEndT);

        consignMapperIn.setBillTimeKeyBeg(CommonUtil.LocalDateTimeToSecond(billTimeBegT));
        consignMapperIn.setBillTimeKeyEnd(CommonUtil.LocalDateTimeToSecond(billTimeEndT));

        consignMapperIn.setBillTimeStrBeg(LocalDateTimeUtil.formatNormal(billTimeBegT));
        consignMapperIn.setBillTimeStrEnd(LocalDateTimeUtil.formatNormal(billTimeEndT));

        consignMapperIn.setGroup(Arrays.asList("item_id"));
        consignMapperIn.setHeaderJoin(headerJoin);
        consignMapperIn.setItemJoin(itemJoin);
        consignMapperIn.setOrderBy(orderBy);
        consignMapperIn.setBillTimeMode(billTimeMode);
        return consignMapperIn;
    }
}
